package com.qf.bank.redis.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;

/**
 * @author 惠佳旭
 * @date 2019/12/4
 */
@Configuration
public class RedisConfig {

  @Bean
  public JedisConnectionFactory jedisConnectionFactory() {
    return new JedisConnectionFactory();
  }

  @Bean
  public RedisTemplate redisTemplate(@Autowired JedisConnectionFactory jedisConnectionFactory) {
    // 设置redisTemplate对象配置参数
    RedisTemplate redisTemplate = new RedisTemplate();
    // 设置redisTemplate对key值的序列转换器
    redisTemplate.setKeySerializer(new RedisUtilsSerializable());
    redisTemplate.setValueSerializer(new RedisUtilsSerializable());
    redisTemplate.setConnectionFactory(jedisConnectionFactory);
    return redisTemplate;
  }
}
